﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Model1;

namespace SECOMPV2.Controllers
{
    public class SpecificatieController : Controller
    {
        private Model1Container db = new Model1Container();

        //
        // GET: /Specificatie/

        public ActionResult Index()
        {
            return View(db.Specificaties.ToList());
        }

        //
        // GET: /Specificatie/Details/5

        public ActionResult Details(int id = 0)
        {
            Specificatie specificatie = db.Specificaties.Find(id);
            if (specificatie == null)
            {
                return HttpNotFound();
            }
            return View(specificatie);
        }

        //
        // GET: /Specificatie/Create

        public ActionResult Create()
        {
            ViewBag.Naam = new SelectList(db.Groeps, "Id", "Naam","Selecteer een groep");
            List<SelectListItem> items = new List<SelectListItem>();
            items.Add(new SelectListItem { Text = "Textueel", Value = "0" });
            items.Add(new SelectListItem { Text = "Binair", Value = "1" });
            ViewBag.Type = items;
            return View();
        }

        //
        // POST: /Specificatie/Create

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include = "Naam,Type,Groep")] Specificatie specificatie, string[] Naam)
        {
            if (ModelState.IsValid)
            {

                specificatie.Groep = db.Groeps.Find(Convert.ToInt32(Naam[1]));
                Specificatie.Add(db,specificatie);
                return RedirectToAction("Index");
            }

            return View(specificatie);
        }

        //
        // GET: /Specificatie/Edit/5

        public ActionResult Edit(int id = 0)
        {
            Specificatie specificatie = db.Specificaties.Find(id);
            if (specificatie == null)
            {
                return HttpNotFound();
            }
            return View(specificatie);
        }

        //
        // POST: /Specificatie/Edit/5

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(Specificatie specificatie)
        {
            if (ModelState.IsValid)
            {
                db.Entry(specificatie).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(specificatie);
        }

        //
        // GET: /Specificatie/Delete/5

        public ActionResult Delete(int id = 0)
        {
            Specificatie specificatie = db.Specificaties.Find(id);
            if (specificatie == null)
            {
                return HttpNotFound();
            }
            return View(specificatie);
        }

        //
        // POST: /Specificatie/Delete/5

        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            Specificatie specificatie = db.Specificaties.Find(id);
            db.Specificaties.Remove(specificatie);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}